﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DrinkTest.Question;
using System.Collections;

namespace DrinkTest.Answer
{
    class Jimson: IDrinkTest
    {
        public long GetSumSat(int[] S, int[] A)
        {
            if (S.Length != A.Length)
            {
                return 0;
            }

            List<DS> list = new List<DS>();

            for (int i = 0; i < A.Length; i++)
            {
                list.Add(new DS(A[i], S[i]));
            }

            list = (from n in list orderby n.s descending select n).ToList();

            int t = 0;
            long ss = 0;
            int counter =100;

            foreach (DS item in list)
            {
                if (counter == 0)
                {
                    break;
                }
                if (item.a < counter)
                {
                    t += item.a;
                    ss += item.a * item.s;
                }
                else
                {
                    ss += item.s * counter;
                    t += counter;
                }

                counter = 100 - t;
            }

            if (t < 100)
            {
                ss = -1;
            }


            return ss;

        }
    }

    class DS
    {
        public int s { get; set; }
        public int a { get; set; }

        public DS(int aa, int ss)
        {
            a = aa;
            s = ss;
        }
    }
}
